import request from '@/utils/request'

// ==================== 文章管理 ====================

// 分页查询文章
export function getArticlePage(params) {
  return request({
    url: '/article/pageArticle', 
    method: 'get',
    params
  })
}

// 获取文章详情
export function getArticleDetail(id) {
  return request({
    url: `/article/getArticleById/${id}`,
    method: 'get'
  })
}

// 创建文章
export function createArticle(data) {
  return request({
    url: '/article/addOrUpdateArticle',
    method: 'post',
    data
  })
}

// 更新文章
export function updateArticle(data) {
  return request({
    url: '/article/addOrUpdateArticle',
    method: 'post',
    data
  })
}

// 删除文章
export function deleteArticle(id) {
  return request({
    url: `/article/deleteArticle/${id}`,
    method: 'delete'
  })
}

// 批量删除文章
export function deleteBatchArticle(ids) {
  return request({
    url: '/article/deleteBatch',
    method: 'post',
    data: ids
  })
}

// 发布文章
export function publishArticle(id) {
  return request({
    url: `/article/publish/${id}`,
    method: 'post'
  })
}

// 下架文章
export function unpublishArticle(id) {
  return request({
    url: `/article/unpublish/${id}`,
    method: 'post'
  })
}

// 更新文章状态
export function updateArticleStatus(id, status) {
  return request({
    url: `/article/updateStatus/${id}`,
    method: 'put',
    data: { status }
  })
}

// 获取热门文章
export function getHotArticles(limit = 10) {
  return request({
    url: '/article/getHotArticles',
    method: 'get',
    params: { limit }
  })
}

// 搜索文章
export function searchArticles(keyword, limit = 20) {
  return request({
    url: '/article/search',
    method: 'get',
    params: { keyword, limit }
  })
}

// ==================== 文章分类管理 ====================

// 获取分类列表
export function getArticleCategoryList() {
  return request({
    url: '/article-category/categoryList',
    method: 'get'
  })
}

// 获取分类详情
export function getArticleCategoryDetail(id) {
  return request({
    url: `/article-category/categoryDetail/${id}`,
    method: 'get'
  })
}

// 创建分类
export function createArticleCategory(data) {
  return request({
    url: '/article-category/addOrUpdateCategory',
    method: 'post',
    data
  })
}

// 更新分类
export function updateArticleCategory(data) {
  return request({
    url: '/article-category/addOrUpdateCategory',
    method: 'post',
    data
  })
}

// 删除分类
export function deleteArticleCategory(id) {
  return request({
    url: `/article-category/deleteCategory/${id}`,
    method: 'delete'
  })
}

// 获取分类树
export function getArticleCategoryTree() {
  return request({
    url: '/article-category/tree',
    method: 'get'
  })
}

// ==================== 标签管理 ====================

// 获取标签列表
export function getTagList() {
  return request({
    url: '/tag/listTags',
    method: 'get'
  })
}

// 分页查询标签
export function getTagPage(params) {
  return request({
    url: '/tag/pageTag',
    method: 'get',
    params
  })
}

// 获取标签详情
export function getTagDetail(id) {
  return request({
    url: `/tag/tagDetail/${id}`,
    method: 'get'
  })
}

// 创建标签
export function createTag(data) {
  return request({
    url: '/tag/addOrUpdateTag',
    method: 'post',
    data
  })
}

// 更新标签
export function updateTag(data) {
  return request({
    url: '/tag/addOrUpdateTag',
    method: 'post',
    data
  })
}

// 删除标签
export function deleteTag(id) {
  return request({
    url: `/tag/deleteTag/${id}`,
    method: 'delete'
  })
}

// 批量删除标签
export function deleteBatchTag(ids) {
  return request({
    url: '/tag/deleteBatch',
    method: 'post',
    data: ids
  })
}

// 获取热门标签
export function getPopularTags(limit = 20) {
  return request({
    url: '/tag/popular',
    method: 'get',
    params: { limit }
  })
}
